package com.luoke.pojo.dto;

import com.luoke.dao.AttributeDao;
import com.luoke.pojo.entity.Attribute;
import com.luoke.util.myjdbc.QueryWrapper;
import com.luoke.util.myjdbc.SQLEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BattleInfoDTO {
    private String player1Name;
    private String player2Name;
    private String player1ActivePet;
    private String player2ActivePet;
    private Attribute player1PetAttribute; //玩家1的宠物属性
    private Attribute player2PetAttribute; //玩家2的宠物属性
    private int player1PetLevel;            // 玩家1的宠物等级
    private int player2PetLevel;            // 玩家2的宠物等级


    // 根据玩家名获取出战宠物名
    public String getActivePetByPlayerName(String playerName) {
        if (playerName.equals(player1Name)) {
            return player1ActivePet;
        } else if (playerName.equals(player2Name)) {
            return player2ActivePet;
        } else {
            return null; // 玩家不在这场对战中
        }
    }

    // 根据玩家名修改对应的出战宠物名
    public boolean setActivePetByPlayerName(String playerName, String newPetName, AttributeDao attributeDao) {
        if (playerName.equals(player1Name)) {
            this.player1ActivePet = newPetName;
            this.player1PetAttribute = attributeDao.getPetAttributeByPetName(newPetName);
            this.player1PetLevel = attributeDao.getPetLevelByPetName(playerName,newPetName); // 获取宠物等级
            return true; // 修改成功
        } else if (playerName.equals(player2Name)) {
            this.player2ActivePet = newPetName;
            this.player2PetAttribute = attributeDao.getPetAttributeByPetName(newPetName);
            this.player2PetLevel = attributeDao.getPetLevelByPetName(playerName,newPetName); // 获取宠物等级
            return true; // 修改成功
        } else {
            return false; // 玩家名不匹配，修改失败
        }
    }

    // 根据玩家名获取当前宠物等级
    public int getPetLevelByPlayerName(String playerName) {
        if (playerName.equals(player1Name)) {
            return player1PetLevel;
        } else if (playerName.equals(player2Name)) {
            return player2PetLevel;
        } else {
            throw new IllegalArgumentException("玩家名不在对战中！");
        }
    }


    /**
     * 根据玩家名获取当前宠物属性
     *
     * @param playerName 玩家名
     * @return 当前宠物的属性对象
     */
    public Attribute getPetAttributeByPlayerName(String playerName) {
        if (playerName.equals(player1Name)) {
            return player1PetAttribute;
        } else if (playerName.equals(player2Name)) {
            return player2PetAttribute;
        } else {
            return null; // 玩家名不在这场对战中
        }
    }


    private void setAttribute() {

    }


}
